var app = angular.module('managerApp', ['ngRoute', 'ui.bootstrap', 'angularFileUpload', 'ngWebSocket'])
// app.controller('foodCtrl', function ($scope, $route) { $scope.$route = $route; });
// app.controller('orderCtrl', function ($scope, $route) { $scope.$route = $route; });

var socket;
if (!socket) {
    socket = io.connect('http://localhost:3001');
}
var updateFunc = function() {console.log('no binding..')};
var getUpdateFunc = function(data) {updateFunc(data)};
socket.on('update', getUpdateFunc);

app.config(function ($routeProvider) {
    $routeProvider.
        when('/food', {
            templateUrl: 'food.html',
            controller: 'foodCtrl'
        }).
        when('/order', {
            templateUrl: 'order.html',
            controller: 'orderCtrl'
        }).
        otherwise({
            redirectTo: '/food'
        });
});

app.factory('socketio', function () {
    var methods = {
        getSocket: function () {
            return socket;
        },
        setFunc: function (func) {
            updateFunc = func;
        }
    };
    return methods;
});

module.exports = app;